//
//  SafePwdViewController.m
//  AppleMarket
//
//  Created by yangy on 08/11/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "SafePwdAlterViewController.h"

// view
#import "SafeMainView.h"
// viewModel
#import "SafePwdViewModel.h"

@interface SafePwdAlterViewController ()
@property (nonatomic, strong) SafeMainView *mainView;
@property (nonatomic, strong) SafePwdViewModel *viewModel;
@end

@implementation SafePwdAlterViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.mainView];
    [self bindViewModel];
}

- (void)bindViewModel
{
    @weakify(self);
    
    [self.viewModel.closeSubject subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    
    [self.viewModel.completeSubject subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        [self dismissViewControllerAnimated:YES completion:^{
            if(self.completeHandler){
                self.completeHandler(self.viewModel.pwdStr_);
            }
        }];
    }];
}

- (SafeMainView *)mainView
{
    if(!_mainView){
        _mainView = [[SafeMainView alloc] initWithFrame:self.view.bounds viewModel:self.viewModel];
    }
    return _mainView;
}

- (SafePwdViewModel *)viewModel{
    if(!_viewModel){
        _viewModel = [[SafePwdViewModel alloc] init];
    }
    return _viewModel;
}

@end
